(cond-expand
 (modules (import (only (chibi test) test-begin test-assert test test-error test-end)))
 (else #f))

(import (scheme base))
(import (scheme write))
(import (clock leap-seconds))

(test-begin "(clock leap-seconds")

(test-assert (eqv? (leap-seconds-before-utc-day 15523) 25))
(test-assert (eqv? (leap-seconds-before-utc-day 15522) 25))
(test-assert (eqv? (leap-seconds-before-utc-day 15521) 24))
(test-assert (eqv? (leap-seconds-before-utc-day 14246) 24))
(test-assert (eqv? (leap-seconds-before-utc-day 14245) 24))
(test-assert (eqv? (leap-seconds-before-utc-day 14244) 23))
(test-assert (eqv? (leap-seconds-before-utc-day   731)  0))
(test-assert (eqv? (leap-seconds-before-utc-day   730)  0))
(test-assert (eqv? (leap-seconds-before-utc-day   365)  0))
(test-assert (eqv? (leap-seconds-before-utc-day     0)  0))
(test-assert (eqv? (leap-seconds-before-utc-day  -365)  0))
(test-assert (eqv? (leap-seconds-before-utc-day  -731)  0))
(test-assert (eqv? (leap-seconds-before-utc-day -1096)  0))
(test-assert (eqv? (leap-seconds-before-utc-day -1461)  0))
(test-assert (eqv? (leap-seconds-before-utc-day -1826)  0))
(test-assert (eqv? (leap-seconds-before-utc-day -2192)  0))
(test-assert (eqv? (leap-seconds-before-utc-day -2557)  0))
(test-assert (eqv? (leap-seconds-before-utc-day -2922)  0))
(test-assert (eqv? (leap-seconds-before-utc-day -3287)  0))

(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400 15522) 35 +1)) 25))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400 15522) 35  0)) 25))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400 15522) 35 -1)) 24))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400 14245) 34 +1)) 24))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400 14245) 34  0)) 24))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400 14245) 34 -1)) 23))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400   730) 10 +1))  0))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400   730) 10  0))  0))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400   730) 10 -1))  0))
(test-assert
 (eqv? (leap-seconds-before-tai-second (+ (* 86400   365)))  0))
(test-assert
 (eqv? (leap-seconds-before-tai-second 0) 0))

(test-end)
